"""
Case Type   : borrow_memory
Case Name   : 直接安装数据库，执行gs_om -t query_upgrade_records
Create At   : 2025/4/29
Owner       : @li-xin12345
Description :
    1、各节点执行gs_om -t query_upgrade_records
Expect      :
    1、报错No upgrade records available.
    [Errno 2] No such file or directory: '.../cluster/tool/upgradeRecord.txt'
History     :
"""

import os
import unittest

from yat.test import Node
from yat.test import macro

from testcase.utils.Logger import Logger


class UpgradeRecordsTest(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_node_sh = Node('PrimaryDbUser')
        self.std1_node_sh = Node('Standby1DbUser')
        self.std2_node_sh = Node('Standby2DbUser')
        self.nodes = [self.pri_node_sh, self.std1_node_sh, self.std2_node_sh]

    def test_upgrade_records(self):
        text = ('-----step1:各节点执行gs_om -t query_upgrade_records;'
                'expect:报错No upgrade records available-----')
        self.log.info(text)
        cmd = (f'source {macro.DB_ENV_PATH}; '
               f'gs_om -t query_upgrade_records;')
        for node in self.nodes:
            self.log.info(f'--{node}执行gs_om -t query_upgrade_records--')
            res = node.sh(cmd).result()
            self.log.info(res)
            self.assertIn('No upgrade records available.', res,
                          '执行失败：' + text)
            self.assertIn('[Errno 2] No such file or directory', res,
                          '执行失败：' + text)

    def tearDown(self):
        text = '-----无需清理环境-----'
        self.log.info(text)
        self.log.info(f'-----{os.path.basename(__file__)} end-----')